<?php

namespace App\Http\Controllers\Api;

use Illuminate\Http\Request;
use App\Models\Project;
use App\Transformers\ProjectTransformer;

class ProjectsController extends Controller
{
	/** [index 项目信息列表] */
    public function index()
    {
    	return $this->response->collection(Project::all(), new ProjectTransformer());
    }


    public function show(Project $project)
    {
    	return $this->response->item($project, new ProjectTransformer());
    }

    /** [store 新增] */
    public function store(Request $request, Project $project)
    {
    	$project->fill($request->all());
    	$project->save();

    	return $this->response->item($project, new ProjectTransformer())->setStatusCode(201);
    }

    public function update(Request $request, Project $project)
    {
    	$project->fill($request->all());
    	$project->update();

    	return $this->response->item($project, new ProjectTransformer());
    }

    public function destroy(Project $project)
    {
    	$project->delete();
        return $this->response->noContent();
    }
}
